/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package z.h.w.jar.data.time.period;

import z.h.w.jar.data.time.Attr;
import z.h.w.jar.data.time.Time;
import z.h.w.jar.data.time.Unit;

/**
 *
 * @author EnzoZhong
 */
public enum PeriodAttr implements Lastable {

   /**
    * 一月份
    */
   JANUARY( "01" , 31.0 ),
   /**
    * 二月
    */
   FEBRUARY( "02" , 28.25 ),
   /**
    * 三月
    */
   MARCH( "03" , 31.0 ),
   /**
    *
    */
   APRIL( "04" , 30.0 ),
   /**
    *
    */
   MAY( "05" , 31.0 ),
   /**
    *
    */
   JUNE( "06" , 30.0 ),
   /**
    *
    */
   JULY( "07" , 31.0 ),
   /**
    *
    */
   AUGUST( "08" , 31.0 ),
   /**
    *
    */
   SEPTEMBER( "09" , 30.0 ),
   /**
    *
    */
   OCTOBER( "10" , 31.0 ),
   /**
    *
    */
   NOVEMBER( "11" , 30.0 ),
   /**
    *
    */
   DECEMBER( "12" , 31.0 ),
   /**
    * 星座
    */
   CAPRICORN( "1222" , "0119" ),
   /**
    *
    */
   AQUARIUS( "0120" , "0218" ),
   /**
    *
    */
   PISCIS( "0219" , "0320" ),
   /**
    *
    */
   ARIES( "0321" , "0419" ),
   /**
    *
    */
   HALCYONE( "0420" , "0520" ),
   /**
    *
    */
   GEMINI( "0521" , "0621" ),
   /**
    *
    */
   CANCER( "0622" , "0722" ),
   /**
    *
    */
   LEO( "0622" , "0722" ),
   /**
    *
    */
   VIRGO( "0823" , "0922" ),
   /**
    *
    */
   LIVRA( "0923" , "1023" ),
   /**
    *
    */
   SCORPIO( "1024" , "1122" ),
   /**
    *
    */
   SQGITTARIUS( "1123" , "1221" );
   private Time start;
   private Time end;

   private PeriodAttr ( String start , String end ) {
      Integer b = Integer.parseInt( start );
      Integer e = Integer.parseInt( end );

      String preYear = Time.born().offset( -0.99 , Unit.YEAR ).tell( Attr.YEAR );
      String nowYear = Time.born().tell( Attr.YEAR );
      if ( b < e ) {
         preYear = nowYear;
      }
      this.start = Time.born( preYear + start );
      this.end = Time.born( Time.born( nowYear + end ).offset( 1.0 , Unit.DAY ).getTime() - 1 );
   }

   private PeriodAttr ( String month , Double mul ) {
      this.start = Time.born( Time.born().tell( Attr.YEAR ) + month );
      this.end = Time.born( this.start.offset( mul , Unit.DAY ).getTime() - 1 );
   }

   @Override
   public Time getEnd () {
      return this.end;
   }

   @Override
   public Time getStart () {
      return this.start;
   }
}
